import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:speed_random/colors_data.dart';
import 'package:speed_random/common/common_fuc.dart';

// 添加颜色选择弹窗方法
Future<void> zdySelectColorConfirm(
    BuildContext context,
    String currentColor,
    Function(String) onColorSelected, {
      List<String>? colors,
      String dialogTitle = '选择颜色',
    }) async {
  final colorList = colors ?? colorsData.getColors();

  await showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text(dialogTitle.tr),
        content: SizedBox(
          width: double.maxFinite,
          child: GridView.builder(
            shrinkWrap: true,
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 5,
              crossAxisSpacing: 8,
              mainAxisSpacing: 8,
            ),
            itemCount: colorList.length,
            itemBuilder: (context, index) {
              return GestureDetector(
                onTap: () {
                  Navigator.of(context).pop();
                  onColorSelected(colorList[index]);
                },
                child: Container(
                  decoration: BoxDecoration(
                    color: commonFuc.hexToColor(colorList[index]),
                    borderRadius: BorderRadius.circular(8),
                    border: currentColor == colorList[index]?Border.all(
                      color: Colors.green,
                      width: 5,
                    ):null,
                  ),
                ),
              );
            },
          ),
        ),
      );
    },
  );
}